package com.springboot;

import lombok.extern.slf4j.Slf4j;
import org.slf4j.MDC;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
@Slf4j
public class ApplicationRunnerDemo implements ApplicationRunner, Ordered {

    @PostConstruct
    public void init() {
        System.out.println("ApplicationRunnerDemo中的@PostConstruct代码成功执行");
    }


    @Override
    public void run(ApplicationArguments args) throws Exception {
        System.out.println("ApplicationRunner: 在SpringApplication运行时会执行的代码1");
        MDC.put("variableKey", "A1");
        log.warn("这是由ApplicationRunnerDemo记录的日志");
    }

    @Override
    public int getOrder() {
        //数字越大表示优先度越低
        return 1;
    }
}
